#ifndef NOSAL_CORE_TEST_DOMAIN_H_
#define NOSAL_CORE_TEST_DOMAIN_H_

#include "nosal/core/error_code.h"
#include "nosal/core/error_domain.h"
#include "nosal/core/exception.h"

using namespace netaos;
enum class TestErrc : nosal::core::ErrorDomain::CodeType
{
    some_error = 1,
    another_error,
};

struct TestException : public nosal::core::Exception
{
    explicit TestException(nosal::core::ErrorCode err) noexcept
        : Exception(err)
    { }
};

class TestErrorDomain final : public nosal::core::ErrorDomain
{
public:
    using Errc = TestErrc;
    using Exception = TestException;

    constexpr TestErrorDomain() noexcept
        : ErrorDomain(1234)
    { }

    char const* Name() const noexcept override
    {
        return "dummy";
    }

    char const* Message(ErrorDomain::CodeType errorCode) const noexcept override
    {
        static_cast<void>(errorCode);
        return "dummy";
    }

    void ThrowAsException(nosal::core::ErrorCode const& errorCode) const noexcept(false) override
    {
        nosal::core::ifc::ThrowOrTerminate<Exception>(errorCode);
    }
};

constexpr TestErrorDomain g_testErrorDomain;

inline constexpr nosal::core::ErrorDomain const& GetTestErrorDomain() noexcept
{
    return g_testErrorDomain;
}

inline constexpr nosal::core::ErrorCode MakeErrorCode(TestErrc code,
    nosal::core::ErrorDomain::SupportDataType data) noexcept
{
    return nosal::core::ErrorCode(static_cast<nosal::core::ErrorDomain::CodeType>(code), GetTestErrorDomain(), data);
}

#endif  // NOSAL_CORE_TEST_DOMAIN_H_
